﻿
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace QLab.IO.Files
{
  public class CustomFile
  {

    public static bool IsRegularFilePath(string path)
    {
      Regex r = new Regex(@"^(([a-zA-Z]\:)|(\\))(\\{1}|((\\{1})[^\\]([^/:*?<>""|]*))+)$");
      return r.IsMatch(path);
    }

    public static bool IsRegularFileName(string FileName)
    {
      FileName = FileName.Trim();
      if (FileName.Length.Equals(0))
        return false;

      return FileName.IndexOfAny(Path.GetInvalidFileNameChars()).Equals(-1) ? true : false;
    }

    public static bool SaveText(string FileName, string Buffer)
    {
      try
      {
        StreamWriter sw = new StreamWriter(FileName);
        sw.Write(Buffer);
      }
      catch
      {
        return false;
      }
      return true;
    }

    public static string LoadText(string FileName)
    {
      string text = String.Empty;
      try
      {
        StreamReader sr = File.OpenText(FileName);
        text = sr.ReadToEnd();
        sr.Close();
      }
      catch { }


      return text;
    }

  }
}
